//k1 升级更新 2021.7.3

AT_DH_Sides = [east,west,resistance];
AT_DH_Terminals = ["O_UavTerminal","B_UavTerminal","I_UavTerminal"];
AT_DH_DronesPacked = [["O_UAV_01_backpack_F","B_UAV_01_backpack_F","I_UAV_01_backpack_F"],["O_UAV_06_backpack_F","B_UAV_06_backpack_F","I_UAV_06_backpack_F"],["O_UAV_06_medical_backpack_F","B_UAV_06_medical_backpack_F","I_UAV_06_medical_backpack_F"]]; //
AT_DH_Drones = ["O_UAV_01_F","B_UAV_01_F","I_UAV_01_F"];

at_fnc_dh_init = {
	player addAction ["入侵UAV终端", at_fnc_dh_hackUAVTerminal, [],1,false,true,"", "_this call at_fnc_dh_terminalCheck"];
	player addAction ["入侵UAV背包", at_fnc_dh_hackUAVBackpack, [],1,false,true,"", "_this call at_fnc_dh_backpackCheck"];
};

at_fnc_dh_hackUAVTerminal = {
	_unit = _this select 1;
	_side = side _unit;
	_sideNumber = AT_DH_Sides find _side;
	if (_sideNumber < 0) exitwith {systemchat "你的阵营没有找到"};
	_unitItems = items _unit;
	{
		if ((_unitItems find _x) != -1 && {_forEachIndex != _sideNumber}) exitwith {
			[[_unit,"AinvPknlMstpSlayWrflDnon_medic"],"at_fnc_dh_switchMove",true] call BIS_fnc_MP;
			[_unit,_x,(AT_DH_Terminals select _sideNumber)] spawn {
				sleep 6;
				if (alive (_this select 0)) then {
					(_this select 0) removeItem (_this select 1);
					(_this select 0) addItem (_this select 2);
				};
			};
		};
	} forEach AT_DH_Terminals;
};
at_fnc_dh_hackUAVBackpack = {
	_unit = _this select 0;
	_side = side _unit;
	_sideNumber = AT_DH_Sides find _side;
	if (_sideNumber < 0) exitwith {systemchat "你的阵营没有找到"};
	_backpack = backpack _unit;
	{
		_arr = _x;
		if (_backpack in _arr) exitwith {
			{
				if (_backpack == _x && {_forEachIndex != _sideNumber}) exitwith {
					[[_unit,"AinvPknlMstpSlayWrflDnon_medic"],"at_fnc_dh_switchMove",true] call BIS_fnc_MP;
					[_unit,(_arr select _sideNumber)] spawn {
						sleep 6;
						if (alive (_this select 0)) then {
							removeBackpack (_this select 0);
							(_this select 0) addBackpack (_this select 1);
						};
					};
				};
			} forEach _arr;
		};
	} forEach AT_DH_DronesPacked;
};

at_fnc_dh_terminalCheck = {
	_unit = _this;
	_side = side _unit;
	_sideNumber = AT_DH_Sides find _side;
	if (_sideNumber < 0) exitwith {false};
	_return = false;
	_unitItems = items _unit;
	{
		if (_forEachIndex != _sideNumber && {_x in _unitItems}) exitwith {_return = true};
	} forEach AT_DH_Terminals;
	_return
};
at_fnc_dh_backpackCheck = {
	_unit = _this;
	_side = side _unit;
	_sideNumber = AT_DH_Sides find _side;
	if (_sideNumber < 0) exitwith {false};
	_backpack = backpack _unit;
	_return = false;
	{
		_find = _x find _backpack;
		if (_find != -1 && {_find != _sideNumber}) exitwith {_return = true};
	} forEach AT_DH_DronesPacked;
	_return
};
AT_FNC_dh_Switchmove = {
	private ["_unit","_anim"];
	_unit = _this select 0;
	_anim = _this select 1;
	_unit switchmove _anim;	
};

